// 首页
// http://t.xiaofeilong.net/m/#/

// 登录
// http://t.xiaofeilong.net/m/#/pages/user/phone

// 接单
// http://t.xiaofeilong.net/api/task/status


function setToken() {
    let token = Android.getMap("token")
    let arr = token.split(",")[0]
    sessionStorage.setItem("token", arr[0])
}
setToken()


function getAndroidToken() {
    let token = localStorage.getItem("token").replace(/^"|"$/g, '');
    let uid = localStorage.getItem("uid").replace(/^"|"$/g, '');
    if (!uid) {
        return ""
    }
    uid = JSON.parse(uid)
    return token + "," + uid["data"]
}
getAndroidToken()




function getParameterHandler() {
    let token = parameter.getMap("token")
    token = token.split(",")

    let headers = {}
    let body = {
        "uid": token[1],
        "token": token[0]
    }
    let strUrl = ``
    let url = parameter.getMap("url") + strUrl
    return {
        mediaType: "form",
        requestType: "POST",
        url: url,
        headers: JSON.stringify(headers),
        body: JSON.stringify(body)
    }
}
getParameterHandler()




function getResponse() {
    let res = response.getMap("res")
    let code = "500"
    let message = "接单中"
    let dataKey = ""
    let dataValue = ""


    res = JSON.parse(res)
    if (res["code"] == 0 && res["cancelCount"] > 0) {
        code = "200"
        message = "接单成功，请尽快完成"
    } else if (res["code"] == 0 && res["cancelCount"] <= 0) {
        code = "500"
        message = "接单中..."
    } else {
        code = "300"
        message = res["msg"]
    }
    return {
        code: code,
        message: message,
        dataKey: dataKey,
        dataValue: dataValue
    }
}
getResponse()
